Skip to main content

Testing Strategy

This document explains the testing approach for the NAVIGO project, covering unit tests, integration tests, and API tests, including what to test, how to test, and the tools used.


1. Unit Testing with Jest

Scope of Unit Tests

  1. React Components Rendering

    • Verify components render correctly with default props.
    • Test conditional rendering (e.g., active vs. completed quests, badges unlocked).
    • Ensure UI elements like buttons, modals, forms, lists, and notifications appear correctly.
    • Test user interaction feedback (clicks, hover effects, disabled states).
    • Validate that components respond correctly to props and context changes.
  2. State Management Logic

    • Test React state updates (useState, useReducer, Context API).
    • Ensure state changes propagate correctly to child components.
    • Validate derived state values (e.g., total points, progress percentages).
    • Test user interactions updating state (e.g., completing a quest updates user points).
  3. Utility Functions

    • Points calculation logic (e.g., awarding points for quests, badges, treasure hunts).
    • Leaderboard sorting and ranking functions.
    • Quest filtering by status, location, or difficulty.
    • Badge/collectible unlocking logic based on points thresholds.
    • Edge cases: zero points, negative points, maximum points, empty data arrays.
  4. Firebase Data Manipulation Functions

    • Reading from Firestore (fetching quests, user data, collectibles, leaderboard data).
    • Writing to Firestore (updating points, adding completed quests, recording verified locations).
    • Updating existing documents (e.g., updating a collectible or quest).
    • Deleting documents (quests, collectibles) and ensuring proper cascade effects.
    • Handling Firestore errors and network failures.
    • Mock Firestore using Jest or Firebase Emulator to avoid touching live data.
  5. Form Validation & Authentication Logic

    • Validate email/password inputs during registration and login.
    • Enforce password requirements: uppercase, lowercase, numeric, special characters, length 8–30.
    • Test Google Sign-In integration.
    • Ensure error messages display correctly for invalid credentials.
  6. Edge Cases & Error Handling

    • Empty or null inputs for functions/components.
    • Invalid or unexpected data from Firebase or APIs.
    • Maximum and minimum value boundaries for points, badges, and leaderboard ranks.
    • Ensure functions handle exceptions gracefully without crashing the app.

Running Unit Tests

npm run test

2. Integration Testing with Cypress

Integration tests ensure that different parts of the application work together correctly, particularly React components interacting with Firebase, APIs, and Google Maps for location verification.

Scope of Integration Tests

2.1 Quest Completion Flow

  • Completing a quest updates user points in Firestore.
  • Verify that the correct points are awarded based on quest difficulty.
  • Badge or collectible rewards are applied to the user inventory.
  • Leaderboard updates reflect the new score in real-time.
  • Check that quest status updates from activecompleted.
  • Ensure error handling when completing a quest with invalid data.
  • Edge cases: completing multiple quests simultaneously, incomplete quests, or invalid quest IDs.

2.2 Collectibles & Badges

  • Collecting a badge updates the user inventory and profile view.
  • Ensure visual feedback appears (pop-ups, notifications, animations).
  • Verify badges and collectibles are displayed correctly in profile.
  • Test unlocking collectibles at exact points thresholds.
  • Edge cases: duplicate collection, missing or corrupt collectible data.

2.3 Navigation & Component Interaction

  • Test smooth page transitions (Dashboard → Quests → Profile → Leaderboard).
  • Ensure modals, dropdowns, and dynamic components render correctly and are functional.
  • Verify interaction between components (e.g., completing a quest updates both user profile and leaderboard).
  • Check for proper state propagation across components.
  • Test responsive behavior on different screen sizes.

2.4 Leaderboard Updates

  • Completing quests or collecting rewards updates leaderboard in real-time.
  • Verify leaderboard filters (weekly, all-time) work correctly.
  • Ensure rankings are accurate after multiple simultaneous updates.
  • Test for proper handling of tied scores.
  • Check that leaderboard reflects points from quests, badges, and collectibles accurately.

2.5 Location Verification Integration

  • Ensure Google Maps API correctly validates user GPS coordinates for quest completion.
  • Test valid, invalid, and out-of-bound coordinates.
  • Verify that points and rewards are only granted if the user is physically at the correct location.
  • Ensure Firestore stores verified locations correctly.
  • Test error handling when Google Maps API fails or returns unexpected data.

Running Integration Tests

Copy code
npx cypress open

3. API Testing with Postman

API tests ensure that server endpoints respond correctly, handle errors gracefully, and integrate with the database and external APIs.

Scope of API Tests

3.1 Quest API

  • Create new quests with valid and invalid data.
  • Retrieve all quests and test filtering using query parameters like status=active or status=completed.
  • Update quests and verify that changes reflect correctly in Firestore.
  • Delete quests and confirm removal from the database.
  • Test edge cases: updating or deleting non-existent quests, missing required fields, invalid data types.
  • Verify response times for API calls.

3.2 Collectibles API

  • Create collectibles (badges/items) with valid and invalid input.
  • Retrieve all collectibles and verify payload correctness.
  • Update collectibles and ensure changes reflect in user inventories.
  • Delete collectibles and confirm removal.
  • Edge cases: unlocking badges at exact points threshold, duplicate collectibles, invalid pointsRequired values.

3.3 Leaderboard API

  • Update user scores and verify that the leaderboard updates in real-time.
  • Retrieve leaderboard data and ensure correct sorting and rankings.
  • Test weekly vs. all-time leaderboard filters.
  • Edge cases: tied scores, simultaneous score updates, invalid user IDs.

3.4 Location API (Google Maps Integration)

  • Verify GPS coordinates for quest completion.
  • Test valid coordinates: confirm points and rewards are awarded correctly.
  • Test invalid or out-of-bound coordinates: ensure rewards are not granted.
  • Check that verified locations are logged correctly in Firestore.
  • Edge cases: multiple location submissions for the same quest, API failures, device location errors.

What to Test

  • Response Status Codes: 200 OK, 201 Created, 400 Bad Request, 401 Unauthorized, 404 Not Found, 500 Server Error
  • Request/Response Payload: Validate correct field types, required fields, and expected values.
  • Authentication:
    • Test endpoints with valid Firebase Auth tokens.
    • Attempt access with invalid or expired tokens and verify rejection.
  • Error Handling:
    • Confirm meaningful error messages for invalid requests.
    • Test API behavior for missing parameters or malformed JSON.
  • Google Maps Integration:
    • Verify that only correct GPS coordinates result in quest completion.
    • Test API response for unreachable coordinates or spoofed locations.

By combining unit, integration, and API testing, NAVIGO ensures reliable functionality across frontend, backend, and real-world location interactions.

This testing strategy verifies that:

  • Components render correctly and state updates work
  • Firebase data reflects user actions accurately
  • APIs respond correctly and securely
  • The application is resistant to errors, invalid inputs, and cheating attempts